package me.zk.practice1.sort;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class CompareDemo {

    public static void main(String[] args) {
        List<Demo1> list = new ArrayList<>();
        Demo1 d1 = new Demo1(1);
        Demo1 d2 = new Demo1(2);
        list.add(d1);
        list.add(d2);
        list.sort(new Comparator<Demo1>() {
            @Override
            public int compare(Demo1 o1, Demo1 o2) {
                return o2.id- o1.id;
            }
        });
        System.out.println(list);

    }
    static class Demo1 implements Comparable<Demo1> {
        int id;

        public Demo1(int id) {
            this.id = id;
        }

        @Override
        public int compareTo(Demo1 o) {
            return this.id - o.id;
        }
    }
}


